/**
 * 
 */
package com.xb.demo22.command;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

/**
 * @author kexue
 *
 */
public class DrawCanvas extends Canvas implements Drawable {

	/** 
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Color color = Color.red;

	private int radius = 6;

	private CommandStack history;

	/**
	 * @param history
	 */
	public DrawCanvas(int width, int height, CommandStack history) {
		super();
		this.history = history;
		setSize(width, height);
		setBackground(Color.WHITE);
	}

	public void draw(int x, int y) {
		Graphics graphics = getGraphics();
		graphics.setColor(color);
		graphics.fillOval(x - radius, y - radius, radius * 2, radius * 2);
	}

	@Override
	public void paint(Graphics g) {
		history.execute();
	}

}
